package com.gitee.ywj1352.client.entity;

import com.gitee.ywj1352.common.Protocol.RpcResponse;
import lombok.Getter;
import lombok.Setter;

import java.util.concurrent.locks.AbstractQueuedSynchronizer;

/**
 * @author wenjie.yang on 2019/10/24.
 */
public class RPCFuture{

    @Getter
    @Setter
    private String requestId;

    @Getter
    @Setter
    private String responseId;

    private RpcResponse response;

    private Syn syn;


    public RPCFuture(String requestId) {
        this.requestId = requestId;
        this.syn = new Syn();
    }

    private class Syn extends AbstractQueuedSynchronizer{
    }

    public RpcResponse getResponse() {
        if (response == null){
            syn.acquire(-1);
        }
        return response;
    }

    public void done(RpcResponse response){
        this.response  = response;
        syn.release(-1);
    }

}
